package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.web.app.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.RoomLabel;
import com.atguigu.lease.web.app.service.RoomLabelService;
import com.atguigu.lease.web.app.mapper.RoomLabelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【room_label(房间&标签关联表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class RoomLabelServiceImpl extends ServiceImpl<RoomLabelMapper, RoomLabel>
    implements RoomLabelService{

    @Autowired
    private LabelInfoService labelInfoService;

    @Override
    public List<LabelInfo> getRoomLabelInfoListById(Long id) {
        List<LabelInfo> labelInfoList = new ArrayList<>();
        List<RoomLabel> roomLabelList = this.list(new LambdaQueryWrapper<RoomLabel>().eq(RoomLabel::getRoomId, id));
        if (roomLabelList != null) {
            for (RoomLabel roomLabel : roomLabelList) {
                LabelInfo labelInfo = new LabelInfo();
                labelInfo.setId(labelInfoService.getById(roomLabel.getLabelId()).getId());
                labelInfo.setType(labelInfoService.getById(roomLabel.getLabelId()).getType());
                labelInfo.setName(labelInfoService.getById(roomLabel.getLabelId()).getName());
                labelInfoList.add(labelInfo);
            }
        }
        return labelInfoList;
    }
}




